package view.transitions;

import java.awt.Graphics;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;

public class CircleOut extends Animator {
	
	private BufferedImage	buffer;

	public CircleOut(BufferedImage from, BufferedImage to) {
		super(from, new BufferedImage(to.getWidth(), to.getHeight(), BufferedImage.TYPE_INT_ARGB));
		this.buffer = to;
	}

	@Override
	public void animate() {
		this.currentFrame++;
		float frameRatio = (float) this.currentFrame / Animator.MAX_FRAMES;
		int radius = (int) (Math.max(this.overlay.getWidth(), this.overlay.getHeight()) / 2 * frameRatio);
		int width = this.overlay.getWidth();
		int height = this.overlay.getHeight();

		Graphics g = this.overlay.getGraphics();
		Ellipse2D circle = new Ellipse2D.Double(width / 2 - radius, height / 2 - radius, radius * 2, radius * 2);
		g.setClip(circle);
		g.drawImage(this.buffer, 0, 0, null);
	}

}
